import { reactive } from "vue";

interface UpAdminPwdV {
  adminName: string;
  oldPwd: string;
  newPwd: string;
  adminDetail: string;
}

export const upAdminPwdV = reactive<UpAdminPwdV>({
  adminName: "",
  oldPwd: "",
  newPwd: "",
  adminDetail: "",
})

interface UpAdminPwdRules {
  oldPwd: ({
    required: boolean;
    message: string;
    trigger: string;
    min?: undefined;
    max?: undefined;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
  newPwd: ({
    required: boolean;
    message: string;
    trigger: string;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
  })[];
}


export const upAdminPwdRules = reactive<UpAdminPwdRules>({
  oldPwd: [
    {
      required: true,
      message: "请输入你的密码",
      trigger: "blur",
    },
    {
      min: 6,
      max: 20,
      message: "密码长度在6到20个字符",
      trigger: "blur",
    },
  ],
  newPwd: [
    {
      required: true,
      message: "请输入你的密码",
      trigger: "blur",
    },
    {
      min: 6,
      max: 20,
      message: "密码长度在6到20个字符",
      trigger: "blur",
    },
  ],
})

interface UpAdminInfoV {
  adminId: string;
  adminName: string;
  adminEmail: string;
  adminPhone: string;
}
export const upAdminInfoV = reactive<UpAdminInfoV>({
  adminId: "",
  adminName: "",
  adminEmail: "",
  adminPhone: "",

})

interface UpAdminInfoRules {
  adminName: ({
    message: string;
    required: boolean;
    trigger: string;
    min?: undefined;
    max?: undefined;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
    required?: undefined;
  })[];

  adminPhone: ({
    required: boolean;
    message: string;
    trigger: string;
    pattern?: undefined;
  } | {
    pattern: RegExp;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
  adminEmail: {
    type: string;
    message: string;
    required: boolean;
    trigger: string;
  }[];
}

export const upAdminInfoRules = reactive<UpAdminInfoRules>({
  adminName: [
    {
      message: "用户名不能为空",
      required: true,
      trigger: "blur",
    },
    {
      min: 2,
      max: 30,
      message: "长度在2到30个字符",
      trigger: "blur",
    },
  ],
  adminPhone: [
    { required: true, message: "请输入手机号", trigger: "blur" },
    // 这个只能验证手机号
    // { pattern:/^0{0,1}(13[0-9]|15[7-9]|153|156|18[7-9])[0-9]{8}$/, message: "请输入合法手机号", trigger: "blur" }
    { pattern: /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/, message: "请输入合法手机号/电话号", trigger: "blur" }
  ],

  adminEmail: [
    {
      type: "email",
      message: "请正确输入邮箱",
      required: true,
      trigger: "blur",
    },
  ],
})

interface AddEnterprise {
  eNature: string;
  eIndustry: string;
  eSizeMin: string;
  eSizeMax: string;
  businessName: string;
  businessSetTime: string;
  businessRegCapital: string;
  businessLegalRepresentative: string;
}

export const addEnterprise = reactive<AddEnterprise>({
  eNature: "",
  eIndustry: "",
  eSizeMin: "",
  eSizeMax: "",
  businessName: "",
  businessSetTime: "",
  businessRegCapital: "",
  // 法人代表
  businessLegalRepresentative: "",
})

interface AddEnterpriseRules {
  eNature: {
    required: boolean;
    message: string;
    trigger: string;
  }[];
  eIndustry: {
    message: string;
    required: boolean;
    trigger: string;
  }[];
  businessName: ({
    message: string;
    required: boolean;
    trigger: string;
    min?: undefined;
    max?: undefined;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
  businessSetTime: {
    type: string;
    required: boolean;
    message: string;
    trigger: string;
  }[];
  businessRegCapital: ({
    message: string;
    required: boolean;
    trigger: string;
    min?: undefined;
    max?: undefined;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
  businessLegalRepresentative: ({
    message: string;
    required: boolean;
    trigger: string;
    min?: undefined;
    max?: undefined;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
}

export const addEnterpriseRules = reactive<AddEnterpriseRules>({
  eNature: [
    {
      required: true,
      message: '请选择公司性质',
      trigger: 'change',
    },
  ],
  eIndustry: [
    {
      message: "此处不能为空",
      required: true,
      trigger: "blur",
    },
  ],
  businessName: [
    {
      message: "此处不能为空",
      required: true,
      trigger: "blur",
    },
    {
      min: 2,
      max: 30,
      message: "长度在2到30个字符",
      trigger: "blur",
    },
  ],

  businessSetTime: [
    {
      type: 'date',
      required: true,
      message: '请选择时间',
      trigger: 'change',
    },
  ],

  businessRegCapital: [
    {
      message: "此处不能为空",
      required: true,
      trigger: "blur",
    },
    {
      min: 1,
      max: 10,
      message: "长度在1到10个字符",
      trigger: "blur",
    },
  ],
  businessLegalRepresentative: [
    {
      message: "此处不能为空",
      required: true,
      trigger: "blur",
    },
    {
      min: 2,
      max: 10,
      message: "长度在2到10个字符",
      trigger: "blur",
    },
  ],
})
